<?php
class memberService extends Service{
    private $table=null;
    
    public function __construct(){
        parent::__construct();
        $this->table=table('member');
    }
    public function li(){
        $return=array();
        $query="select * from `{$this->table}` order by `id` desc";

        $p=new smart_pager($query,$this->m);
        //$p->address('&cat_id=%cat_id%','cat_id',100);
        if($p->total_num>0){
            $return[]=$this->m->mselect($p->query);
            $return[]=$p;
        }
        return $return;
    }
    public function mod($id){
        $id=intval($id);
        if($id>0){
            return $this->model->_f($this->table,$id);
        }
        return false;
    }
    public function mod_($post,$id){
		$uc_user_service=new uc_user;
		$user_id=$id;
        $result=array();
        $vali=validate::check('member',$post,'mod',array('id::!='=>$id));
        if($vali){
    		$username=$post['user_name'];
			$old_password='';
			$password=$post['user_password'];
			$email=$post['email'];
			
			$ucresult = $uc_user_service->system_edit($username, $old_password, $password, $email,1);
			if($ucresult<=0){
				if($ucresult == -1) {
					alert('旧密码不正确！');
					back();
					
				} else if($ucresult == -4) {
					alert('Email 格式有误！');
					back();
					
				} else if($ucresult == -5) {
					alert('Email 不允许注册！');
					back();
					
				} else if($ucresult == -6) {
					alert('该 Email 已经被注册！');
					back();
					
				} else if($ucresult == 0){
					alert('没有做任何修改！');
					back();
					
				} else{
					alert('更新失败！');
					back();
					
				}
			}else{
				$fields='';
				
				if($email!=''){
					$fields.=" `email`='{$email}',";	
				}
				$fields=rtrim($fields,',');
				if($fields!=''){
					$query="update `{$this->table}` set {$fields} where `id`='{$user_id}'";
					$this->m->query($query);
				}
				$result[0]=true;
			}
    	}else{
    		$result[0]=false;
            $result[1]="\\n".implode("\\n",validate::getMsg());
    	}
        return $result;
    }
}